home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0055_Example of TV Dir Collection.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  3KB  |  133 lines

  1. {$X+}
  2. Program ExampleProgram;
  3. {$M $8000,0,655360}
  4. Uses Drivers, Objects, Views, App, Menus, Dialogs, Dos;
  5.   Const
  6.     cmLeft =  101;
  7.  
  8.   Type
  9.     PDirCollection = ^TDirCollection;
  10.     TDirCollection = Object(TSortedCollection)
  11.       Constructor Init;
  12.       Function Compare(Key1, Key2: Pointer): Integer; Virtual;
  13.       Procedure FreeItem(Item: Pointer); Virtual;
  14.     End;
  15.  
  16.     PMStaticText = ^TMStaticText;
  17.     TMStaticText = Object(TStaticText)
  18.       Function GetPalette: PPalette; Virtual;
  19.     End;
  20.  
  21.     PTestDialog = ^TTestDialog;
  22.     TTestDialog = Object(TDialog)
  23.       Function Valid(Command: Word): Boolean; Virtual;
  24.     End;
  25.  
  26.     TTestMain = Object(TApplication)
  27.       Constructor Init;
  28.       Procedure InitStatusLine; Virtual;
  29.       Procedure Run; Virtual;
  30.     End;
  31.   {-------------- TDirCollection -------}
  32.     Constructor TDirCollection.Init;
  33.       Var
  34.         I: Integer;
  35.         Info: SearchRec;
  36.         S: ^String;
  37.       Begin
  38.         TCollection.Init(100, 10);
  39.         FindFirst('*.*', AnyFile, Info);
  40.         While DosError=0 do
  41.           Begin
  42.             New(S);
  43.             S^:=Info.Name;
  44.             Insert(S);
  45.             FindNext(Info);
  46.           End;
  47.       End;
  48.  
  49.     Function TDirCollection.Compare(Key1, Key2: Pointer): Integer;
  50.       Begin
  51.         If String(Key1^)<String(Key2^) then Compare:=-1
  52.         Else If String(Key1^)>String(Key2^) then Compare:=1
  53.         Else Compare:=0;
  54.       End;
  55.  
  56.     Procedure TDirCollection.FreeItem(Item:Pointer);
  57.       Type
  58.         PString = ^String;
  59.       Begin
  60.         Dispose(PString(Item));
  61.       End;
  62.  
  63.  
  64.   {-------------- TStaticText ----------}
  65.     Function TMStaticText.GetPalette: PPalette;
  66.       Begin
  67.         GetPalette := TView.GetPalette{@cMenuBar};
  68.       End;
  69.  
  70.   {-------- TTestDialog --------}
  71.   Function TTestDialog.Valid(Command: Word): Boolean;
  72.     Begin
  73.       Valid:=False;
  74.       Case Command of
  75.         cmLeft:;
  76.       Else
  77.         Valid:=true;
  78.       End
  79.     End;
  80.  
  81.   {-------- TTestMain ----------}
  82.   Constructor TTestMain.Init;
  83.     Var
  84.       StaticText: PMStaticText;
  85.       R: TRect;
  86.     Begin
  87.       TApplication.Init;
  88.       GetExtent(R);
  89.       R.B.Y:=R.A.Y+1;
  90.       StaticText:= New(PMStaticText, Init(R, '                         Welcome to Turbo Vision'));
  91.       Insert(StaticText);
  92.       GetExtent(R);
  93.       R.A.Y:=R.B.Y-1;
  94.       StaticText:= New(PMStaticText,Init(R,' '));
  95.       Insert(StaticText);
  96.       R.Assign(70,24,79,25);
  97.     End;
  98.  
  99.   Procedure TTestMain.InitStatusLine;
  100.     Begin
  101.     End;
  102.  
  103.   Procedure TTestMain.Run;
  104.     Var
  105.       Dialog: PTestDialog;
  106.       ListBox: PListBox;
  107.       DirCollection: PDirCollection;
  108.       ScrollBar: PScrollBar;
  109.       R:TRect;
  110.     Begin
  111.       R.Assign(5,3,30,18);
  112.       Dialog := New(PTestDialog, Init(R, 'My Dialog'));
  113.  
  114.       R.Assign(20,2,21,13);
  115.       ScrollBar:=New(PScrollBar,Init(R));
  116.       Dialog^.Insert(ScrollBar);
  117.       R.Assign(2,2,20,13);
  118.       ListBox:= New(PListBox, Init(R, 1, ScrollBar));
  119.       Dialog^.Insert(ListBox);
  120.       DirCollection:=New(PDirCollection, Init);
  121.       ListBox^.NewList(DirCollection);
  122.       DeskTop^.ExecView(Dialog);
  123.     End;
  124.  
  125.   Var
  126.     TestMain: TTestMain;
  127.  
  128.   Begin
  129.     TestMain.Init;
  130.     TestMain.Run;
  131.     TestMain.Done;
  132.   End.
  133.